package com.example.RuanJianKeShe.Service.manager.update;

import com.alibaba.fastjson.JSON;
import com.example.RuanJianKeShe.Bean.Teacher;
import com.example.RuanJianKeShe.Dao.impl.TeacherDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateTeacherInfo")
public class updateTeacherInfo extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        System.out.println(req.getParameter("msg"));
        Teacher teacher = new Teacher();
        teacher.setTname(req.getParameter("tname"));
        teacher.setTno(Integer.parseInt(req.getParameter("tno")));
        teacher.setTsex(req.getParameter("sex"));
        teacher.setTeakey("123");
        teacher.setTage(Integer.parseInt(req.getParameter("age")));;
        teacher.setTelephone(req.getParameter("telephone"));;
        teacher.setEmail(req.getParameter("email"));
        TeacherDaoImpl teacherDao = new TeacherDaoImpl();
        Boolean flag = teacherDao.setTeacherById(teacher);
        if (flag==true){
            String jsonString = JSON.toJSONString("success");
            resp.getWriter().write(jsonString);
        }

    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }

}
